package com.bjsxt.userscenter.head.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bjsxt.userscenter.common.controller.BaseController;
import com.bjsxt.userscenter.common.util.ConstatFinalUtil;
import com.bjsxt.userscenter.outer.service.IOuterService;

@Controller
@RequestMapping("/outer/")
public class OutController extends BaseController
{
	@Resource
	private IOuterService outerService;
	
	@ResponseBody
	@RequestMapping(value="/regionList",produces="text/html;charset=UTF-8")
	public String regionList(HttpServletRequest request){
		ConstatFinalUtil.LOGGER.info("--------regionList-----");
		Long st=System.currentTimeMillis();
		JSONObject resultJSON=new JSONObject();
		String json=request.getParameter("json");
		if(json==null){
			json="";
		}
		JSONObject reqJSON=null;
		try{
			reqJSON=(JSONObject)JSON.parse(json);
		}catch(Exception e){
			resultJSON.put("code", "11");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("11"));
		}
		
		try{
			if("1".equalsIgnoreCase(reqJSON.getString("version"))){
				resultJSON=this.outerService.regionList01Service(reqJSON);
			}else{
				resultJSON.put("version", reqJSON.getString("version"));
				resultJSON.put("code", "9");
				resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("9"));
			}
		}catch(Exception e){
			ConstatFinalUtil.LOGGER.error("拼装JSON对象出错了；上行数据:{}",reqJSON,e);
			resultJSON.put("code", "-1");
			resultJSON.put("info", ConstatFinalUtil.INFO_JSON.get("-1")+e.toString());
		}
		long ed=System.currentTimeMillis();
		resultJSON.put("consume", (ed-st)+"毫秒");
		return resultJSON+"";
		
		
	}
}
